/*
 * Created on 2005-3-22
 *
 * Copyright: Bluejay Networks Inc. 2005
 *
 * This software is the proprietary information of Bluejay Networks Inc. 
 * 
 * Use is subject to license terms.
 * 
 */
package com.ims.iaa.swf.button.action;

import com.ims.iaa.swf.ByteArrayUtil;

/**
 * @author ShengMengBai
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public final class GetURLAction extends BaseAction{
    public static final int code = ACTION_GETURL1;
    private final byte[] m_bytData;
    private final int m_iOffset;
    private String m_sURL = "";
    public GetURLAction(byte[] bytData, int iOffset) {
        m_bytData = bytData;
        m_iOffset = iOffset;
	    //System.out.println("find button tag: " + code + " Position: " + iOffset);
    }
//ActionCode			UI8			Action = 0x83
//Length				UI16		Combined length of strings
//UrlString				STRING		Target URL string
//TargetString			STRING		Target string
    public boolean parse(){
        int iStart = m_iOffset;
	    int iActionCode = m_bytData[iStart];
	    //System.out.println("ActionCode " + iActionCode + " Position: " + iStart);
	    if(iActionCode != code){
	        throw new RuntimeException("parse error in GetURLAction class, GetURLAction.code=" + code + " and real code=" + iActionCode);
	    }
	    iStart += 1;
	    int iLen = ByteArrayUtil.toShort(m_bytData, iStart);
	    //System.out.println("String len:  " + iLen + " Position: " + iStart);
	    iStart += 2;
	    
	    m_sURL = ByteArrayUtil.toString(m_bytData, iStart);
	    //System.out.println("URL:  " + m_sURL);
	    return true;
    }
    public String getURL(){
        return m_sURL;
    }
    /* (non-Javadoc)
     * @see com.ims.iaa.swf.SwfObject#getCode()
     */
    public int getCode() {
        return code;
    }

}
